#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define m(a) memset(a,0,sizeof(a))
#define mm(a) memset(a,-1,sizeof(a))
#define mi(a) memset(a,0x3f3f3f3f,sizeof(a))
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 310;
int val[N][N];
int lx[N],ly[N];
int linky[N];
int pre[N];
bool vis[N];
bool visx[N],visy[N];
int slack[N];
int n;
void bfs(int k) {
    int px, py = 0,yy = 0;
	ll d;
    memset(pre, 0, sizeof(pre));
    memset(slack, inf, sizeof(slack));
    linky[py]=k;
    do {
        px = linky[py],d = INF, vis[py] = 1;
        for(int i = 1; i <= n; i++) {
            if(!vis[i]) {
                if(slack[i] > lx[px] + ly[i] - val[px][i])
                    slack[i] = lx[px] + ly[i] - val[px][i], pre[i] = py;
                if(slack[i] < d)
                    d = slack[i], yy = i;
            }
        }
        for(int i = 0; i <= n; i++) {
            if(vis[i])
                lx[linky[i]] -= d, ly[i] += d;
            else
                slack[i] -= d;
        }
        py = yy;
    } while(linky[py]);
    while(py) {
        linky[py] = linky[pre[py]], py=pre[py];
 	}
}
ll KM() {
    memset(lx, 0, sizeof(lx));
    memset(ly, 0, sizeof(ly));
    memset(linky, 0, sizeof(linky));
    for(int i = 1; i <= n; i++){
        memset(vis, 0, sizeof(vis));
		bfs(i);
    }
    ll ans = 0;
    for (int i = 1;i <= n; i++) {
    	ans += val[linky[i]][i];
	}
    return ans;
}
int main() {
    while(cin>>n) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                cin>>val[i][j];
            }
        }
        cout<<KM()<<endl;
    }
    return 0;
}